define(['jquery', 'bootstrap', 'backend', 'table', 'form','echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Table, Form, Echarts, undefined, Template) {

    var Controller = {
        index: function () {

            var myChart2=Echarts.init(document.getElementById('echart'), 'walden');
            var option2 = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                legend: {
                    data: [ '新增工单数量','完成工单数量']
                },
                xAxis: [
                    {
                        type: 'category',
                        data: Config.result.date,
                        axisPointer: {
                            type: 'shadow'
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '合同金额',
                        min: 0,
                        max: Config.result.add,
                        axisLabel: {
                            formatter: '{value} 个'
                        }
                    },
                    {
                        type: 'value',
                        name: '合同数',
                        min: 0,
                        max: Config.result.end,
                        axisLabel: {
                            formatter: '{value} 个'
                        }
                    }
                ],
                series: [
                    {
                        name: '新增工单数量',
                        type: 'bar',
                        data: Config.result.add
                    },
                    {
                        name: '完成工单数量',
                        type: 'bar',
                        data: Config.result.end
                    },
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart2.setOption(option2);
            $(window).resize(function () {
                myChart2.resize();
            });
            var configids = Config.ids;
            $('.sender').on('change', function() {
                var ids = $(this).val();
                if(ids == 0){
                    return false;
                }
                $.post('qingdongams/statistics/customer/staffes',
                    {
                        'typeid':ids
                    },
                    function (data) {
                        $('#c-external_staff_id').html("");
                        for(var i in data){
                            if(configids && configids == i){
                                $('#c-external_staff_id').append('<option value="'+i+'" selected>'+data[i]+'</option>')
                            }else{
                                $('#c-external_staff_id').append('<option value="'+i+'">'+data[i]+'</option>')
                            }
                        }
                        $('select').selectpicker('refresh');
                    }
                );
            });
            $('.sender').trigger('change');
            // Controller.api.bindevent();
            Form.api.bindevent($("form.forms"), function(data,ret){
                //成功的回调,如果返回false,将不会出现提示消息
                window.location.href = ret.url;
                //return false;
            }, function(data, ret){
                //失败的回调,如果返回false,将不会出现提示消息
                //return false;
            }, function(success, error){
                console.log(error)
                console.log(success)
                window.location.href = window.location.pathname+'?'+$(this).serialize();
                return false;
                //如果返回falsle,将阻止表单的提交
                //return false;
                //如果处理成功后我们可以使用Form.api.submit(this, success, error);再次提交表单
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        summary: function () {
            var configids = Config.ids;
            $('.sender').on('change', function() {
                var ids = $(this).val();
                if(ids == 0){
                    $('#c-external_staff_id').text('<option value="0" id="external_staff_id">请选择</option>')
                    return false;
                }
                $.post('qingdongams/statistics/workorder/staffes',
                    {
                        'typeid':ids
                    },
                    function (data) {
                        $('#c-external_staff_id').html("");
                        for(var i in data){
                            if(configids && configids == i){
                                $('#c-external_staff_id').append('<option value="'+i+'" selected>'+data[i]+'</option>')
                            }else{
                                $('#c-external_staff_id').append('<option value="'+i+'">'+data[i]+'</option>')
                            }
                        }
                        $('select').selectpicker('refresh');
                    }
                );
            });
            $('.sender').trigger('chang');
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});